
import java.util.Arrays;
import java.util.Stack;
class MyStack1{
    public int[] elem;
    public int usedSize;
    public MyStack1(){
        this.elem = new int[5];
    }

    public void push(int val){
        if (isFull()){
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[this.usedSize] = val;
        this.usedSize++;
    }

    public int pop(){
        if (isEmpty()){
            throw new RuntimeException("栈为空！");
        }
        int oldVal = this.elem[usedSize - 1];
        this.usedSize--;
        return oldVal;
    }

    public int peek() {
        if (isEmpty()) {
            throw new RuntimeException("栈为空！");
        }
        return this.elem[usedSize - 1];
    }


    public boolean isFull(){
        return this.usedSize == this.elem.length;
    }

    public boolean isEmpty(){
        return this.usedSize == 0;
    }
}
public class MyStack {
    public static void main(String[] args) {
        Stack<Integer> stack = new Stack<>();
        /*stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        System.out.println(stack.pop());
        System.out.println(stack.peek());
        System.out.println(stack.peek());
        System.out.println(stack.empty());
        System.out.println(stack.isEmpty());*/
    }
}
